#include "Protocols/Udp.h"
#include "Protocols/ShowableItem.h"
#include "utilities/ReadablePacket.h"
#include "protocols/ProtocalCode.h"
#include "protocols/ProtocalPool.h"

REGISTER_PROTOCOL(Udp)

using boost::shared_ptr;
 

void UdpHeader::toShowableItems(ShowableItem* root) const
{
	HeaderFormat* header = (HeaderFormat*)mData;
	int pos = mPos;
	ShowableItem* tmp,*flag;

	ShowableItem* proto = createProtocalItem("UDP - Transport Control Protocal",
		mPos,getHeaderLength());
	root->pushChild(proto);

	tmp = createItem("Source Port:",QString::number(getSrcPort()),pos,2);
	proto->pushChild(tmp);

	tmp = createItem("Destination Port:",QString::number(getDstPort()),pos,2);
	proto->pushChild(tmp);

	tmp = createItem("Length:",QString::number(getLength()),pos,2);
	proto->pushChild(tmp);

	tmp = createItem("Checksum:",toHexString(pointer(pos),2),pos,2);
	proto->pushChild(tmp);
}


Udp::Udp():Protocol(UDP,QString("UDP"))
{
}


QString UdpHeader::getSummary() const
{
	return QString().sprintf("%d > %d",(int)getSrcPort(),(int)getDstPort());
}

PacketHeader*
Udp::analyzeProc(ReadablePacket* packet,int low,int high,Protocol*& tip)
{
	UdpHeader* header = new UdpHeader(PROTOCOL_POINTER(Udp),packet->getData(),low,high - low + 1);
	tip = NULL;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	return header;
}